package com.lzy.huijinjiazu.mvp.ui.dialog;

import android.content.Context;
import android.graphics.Rect;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.flyco.dialog.widget.base.BaseDialog;
import com.flyco.roundview.RoundTextView;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.ui.widget.TagGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by long on 2018/1/10.
 */

public class FinanceTagDialog extends BaseDialog<FinanceTagDialog> {

    View mAnchorView;
    TagGroup mTgList;
    private OnClickListener mOnClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.mOnClickListener = onClickListener;
    }

    public FinanceTagDialog(Context context, View view) {
        super(context);
        this.mAnchorView = view;
    }

    public void setData(List<String> data, int position, int color) {
        mTgList.setList(data);
    }

    @Override
    public View onCreateView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_finance_tag, null, false);
        mTgList = view.findViewById(R.id.tg_list);
        return view;
    }

    @Override
    public void setUiBeforShow() {
        mTgList.setOnTagItemClickListener((view, position, tag) -> {
//            for (int i = 0; i < mTgList.getChildCount(); i++) {
//                if(view.getId() == mTgList.getChildAt(i).getId()){
//                    RoundTextView tvView = (RoundTextView) view;
//            tvView.getDelegate().setStrokeColor(0xffe57f14);
//            tvView.setTextColor(0xffe57f14);
//            mOnClickListener.setOnClickListener(position);
//                }
//
//            }
        });


    }

    @Override
    protected void onStart() {
        super.onStart();
        WindowManager.LayoutParams params = getWindow().getAttributes();
        int location[] = new int[2];
        final Rect rect = new Rect();

        //获取显示范围，不包括状态栏
        mAnchorView.getWindowVisibleDisplayFrame(rect);
        //获取anchorView 在屏幕的坐标
        mAnchorView.getLocationOnScreen(location);

        int y = location[1] + mAnchorView.getHeight();
        params.dimAmount = 0;
        params.gravity = Gravity.TOP;
        params.x = location[0];
        params.y = y;
        mLlTop.setBackgroundColor(0x80000000);
        mLlTop.setGravity(Gravity.TOP);
        mLlTop.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mContext.getResources().getDisplayMetrics().heightPixels - y));
    }

    public interface OnClickListener {
        void setOnClickListener(int position);
    }
}
